package com.estore3.src.com.estore.service;

import com.com.estore02.model.Product;
import java.util.Comparator;

/**
 * 商品排序器类，提供多种排序方式
 */
public class ProductSorters {

    // 按商品价格从低到高排序
    public static final Comparator<Product> BY_PRICE_ASC =
            Comparator.comparingDouble(Product::getPrice);

    // 按商品价格从高到低排序
    public static final Comparator<Product> BY_PRICE_DESC =
            BY_PRICE_ASC.reversed();

    // 按商品库存从多到少排序
    public static final Comparator<Product> BY_STOCK_DESC =
            Comparator.comparingInt(Product::getStock).reversed();

    // 按商品名称排序（中文支持）
    public static final Comparator<Product> BY_NAME_ASC =
            Comparator.comparing(Product::getName, String.CASE_INSENSITIVE_ORDER);

    // 按商品ID排序（使用自然排序）
    public static final Comparator<Product> BY_ID_ASC =
            Comparator.comparing(Product::getId);
}